import Vue from 'vue'
import store from './store/index'
import App from './App.vue'
import axios from '../src/axios/index'
// import myToast from '../src/components/toast.vue'
import myToast from '../src/util/toast'
// import axios from 'axios'
// 请求基准路径
import Qs from 'qs'
import 'reset-css'
import 'mint-ui/lib/style.css'
// 修复样式
import './style/reset.css'
import router from './router'
// 移动端适配工具
import 'amfe-flexible'
// 解决移动端click延迟
import FastClick from 'fastclick'

// 引入需要的mint-ui组件
import { Toast } from 'mint-ui';

Vue.prototype.$toast = Toast
// Vue.prototype.$myToast = myToast
Vue.prototype.$myToast = myToast.init()
Vue.prototype.$http = axios
Vue.prototype.qs = Qs

FastClick.attach(document.body)

// 路由守卫
// 防止刷新后vuex数据丢失--利用本地存储
// router.beforeEach((to, from, next) => {
//   if (!store.state.actoken) {
//     // store.state.actoken = localStorage.getItem('actoken')
//     store.commite('getToken', localStorage.getItem('actoken'))
//     next()
//   } else {
//     next()
//   }
// })

// 防止刷新后vuex数据丢失--重新请求
router.beforeEach((to, from, next) => {
  console.log(to);
  if (to.meta.title) {
    document.title = to.meta.title
    store.commit('changeTitle', to.meta.title)
  }
  if (!store.state.actoken) {
    store.dispatch('getMyToken').then(res => {
      next()
    })
  } else {
    next()
  }
})

Vue.config.productionTip = false

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
